package mma;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.snapshot.RobotState;
import robocode.control.testing.RobotTestBed;

/**
 * Tests to see if after a robot that is targeted is destroyed,
 * MizuOnegai finds a new target.
 *
 * @author Matthew Mizumoto
 */
public class TestMizuOnegaiCollisions extends RobotTestBed {
  /**True if the robot made a collision.*/
  boolean collided = false;
  /**True if robot moves moves away after collision.*/
  boolean runAway = false;

  /**
   * Specifies that RamFire and MizuOnegai are to be matched up in this test case.
   *
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.RamFire,mma.MizuOnegai";
  }

  /**
   * This test runs for 10 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if we're at a corner. If so, set the corresponding flag.
   *
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot daCruzer 
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    
    if (robot.getState().equals(RobotState.HIT_ROBOT))  {
      collided = true;
    }
    
    if (collided && robot.getVelocity() < 0)  {
      runAway = true;
    }
    

  }

  /**
   * After the battle, check to see that we've visited the corners.
   *
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Collision", collided);
    assertTrue("Check Run Away", runAway);

  }

}
